#ifndef LIBRARYFUNCTIONS_H_
#define LIBRARYFUNCTIONS_H_

#include "../systemCallLayer/SystemCallLayer.h"
#include "ProcessInfo.h"
#include <string>
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <map>
using namespace std;

class LibraryFunctions {

private:

	SystemCallLayer systemCallLayer;

	//holds the maps of all the processes created in the system
	map <int,ProcessInfo*> processesMap;

	//changed upon context switch:
	string *currentPath;

	//for the exit command of the shell:
	bool shouldExit;
	int parseString(string sStringToParse, string delimChar, vector<string>& rReturnStringArray);

	int mkdir (const char* dirName);

	//flags can be one of the following: "read-only" or "read-and-write"
	int create (const char* fileName, string flags);

	int hdlink (const char* target, const char* newFileName);
	int sflink (const char* target, const char* newFileName);
	int open (const char* fileName, string flags);
	int close (int fd);
	int read (int fd, int numBytes);
	int write (int fd, const char* dataString);
	int writeFile (int fd, const char* fileName);
	int lck_rd (int fd);
	int lck_wr (int fd);
	int rlslck_rd (int fd);
	int rlslck_wr (int fd);
	int lseek (int fd, int offset);
	int rm (const char* fileName);
	int rmdir (const char* dirName);
	int rmdir_r (const char* dirName);
	int ls (const char* dirName);
	int mv (const char* oldfileName, const char* newFileName);
	int cd (const char* newDir);

	bool isValidDirPath(const char* dirName);
	string makeAbsolutePath (const char* path, int numOfDirsBack);
	string makeAbsolutePathForCdAndLs(const char* path, int numOfDirsBack);
	vector<string> parsePath(string sStringToParse);
	const char* clearPath (const char* name);
	int countNumOfDirsBack (const char* path);
	int countNumOfDirsBackForCd (const char* path);
	void removeDotDotAndSlashFromEnd(string& absolutePath);

public:
	LibraryFunctions(int diskSizeInBytes, int dataBlockSize, int numberOfInodes);
	LibraryFunctions();
	virtual ~LibraryFunctions();
	//extracts the parameters of the command from the string and sends them to a proper command function
	int processCommand (vector<string>& userInput);
	int swprc (int newProcessNum);
	int crprc (int id, int parent);
	int batch (const char* fileName);
	//while (true): reads from user and send the command (if not empty) to processCommand
	void run ();
	//TODO - remove:
	void test();
};

#endif /* LIBRARYFUNCTIONS_H_ */
